<template>
  <div>
    <div v-if="row.actions.length>2">
      <a @click="handleClickMore(row.actions[0].name, row)">{{ row.actions ? row.actions[0].label : '' }}</a>
      <Divider type="vertical" />
      <Dropdown @on-click="(name) => handleClickMore(name, row)"
                transfer>
        <a>更多
          <Icon type="ios-arrow-down" /></a>
        <DropdownMenu slot="list">
          <DropdownItem v-for="(item, i) in row.actions.slice(1)"
                        :key="i"
                        :name="item.name">{{ item.label }}</DropdownItem>
        </DropdownMenu>
      </Dropdown>
    </div>
    <div v-else>
      <a v-if="row.actions"
         @click="handleClickMore(row.actions[0].name, row)">{{ row.actions[0].label }}</a>
      <Divider v-if="row.actions && row.actions.length>1"
               type="vertical" />
      <a v-if="row.actions && row.actions.length>1"
         @click="handleClickMore(row.actions[1].name, row)">{{ row.actions[1].label }}</a>
    </div>
    <Modal v-model="auditModal"
           title="商家签名审核">
      <Form ref="formValidate"
            :model="formData"
            :label-width="0">
        <FormItem label=""
                  prop="">
          <Input v-model="formData.note"
                 type="textarea"
                 :autosize="{minRows: 2,maxRows: 5}"
                 placeholder="请输入审核批注，拒绝时，此为必填项"></Input> </FormItem>
      </Form>
      <div slot="footer">
        <Button type="primary"
                :loading="aloading"
                @click.stop="auditSubit('1')">
          <span v-if="!aloading">通过</span>
          <span v-else>Loading...</span>
        </Button>
        <Button type="primary"
                :loading="aloading"
                @click.stop="auditSubit('0')">
          <span v-if="!aloading">拒绝</span>
          <span v-else>Loading...</span>
        </Button>
      </div>
    </Modal>
  </div>
</template>
<script>
    import { ApiRequest } from '@api/basePage';
    import dynamictableactions from '@/mixins/dynamictableactions'; // 混入通用代码
    export default {
        mixins: [
            dynamictableactions
        ],
        data () {
            return {
                auditModal: false,
                formData: {
                    type: [],
                    object: []
                }
            }
        },
        methods: {
            //  操作更多选择
            handleClickMore (name, row) {
                let obj = {}; // 动作的对象信息
                row.actions.forEach(item => {
                    if (name === item.name) {
                        obj = item;
                        return false;
                    }
                })
                this.setTableRowData(row)
                if (obj.handleType === 'link') { // 操作类型为链接时，拼接参数跳转
                    let jumpPath = this.jumpPath + obj.name;
                    this.$router.push({ path: jumpPath, query: { 'uuid': row.uuid } })
                } else if (obj.handleType === 'confirm') { // 操作类型为confirm时 打开modal弹窗
                    if (name === 'Audit') {
                        this.formData = {
                            note: ''
                        };
                        this.auditModal = true;
                    }
                } else if (obj.handleType === 'alert') {

                }
            },
            // 审核通过/拒绝
            auditSubit (state) {
                if (state === '0' && this.formData.note === '') {
                    this.$Message.error('请填写审核意见');
                    return false;
                }
                this.aloading = true;
                let data = {
                    note: this.formData.note,
                    uuid: this.row.uuid,
                    state: state
                }
                ApiRequest(this.requestApi.merchantSignAuditSubit.url, this.requestApi.merchantSignAuditSubit.type, data).then(res => {
                    this.aloading = false;
                    this.$Message.success('操作成功');
                    this.auditModal = false;
                    this.actionsChange();
                })
            }
        }
    }
</script>
